package com.inossem.warehousestorage_inossem.request.outStorage;

import android.content.Context;

import com.google.gson.Gson;
import com.inossem.warehousestorage_inossem.bean.outStorage.OutStoragePickingAddBatchBean;
import com.inossem.warehousestorage_inossem.constant.RequestConstant;
import com.inossem.warehousestorage_inossem.listener.GsonBeanListener;
import com.inossem.warehousestorage_inossem.listener.StringRequestListener;
import com.inossem.warehousestorage_inossem.manage.RequestManage;
import com.inossem.warehousestorage_inossem.model.StringResponse;
import com.inossem.warehousestorage_inossem.request.Request;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by leij on 2017/6/12.
 */

public class OutStoragePickingAddBatchRequest extends Request {

    private static final String IS_SCANNER = "isScanner";//是否为扫描

    private static final String SCANNER_CONTENT = "scannerContent";//扫描结果

    private static final String BATCH = "charg";//批次

    private static final String MATERIEL_CODE = "materielCode";//物料编码

    private static final String FACTORY_CODE = "werks";//是工厂

    private static final String INVENTORY_ADDRESS_CODE = "inventoryAddressCode";//库存地点

    private static final String PICKING_CLASSIFY = "pickingClassify";//领料分类

    private static final String USE_DEPARTMENT = "useDepartment"; //使用部门

    public static String request(Context context, boolean isSCanner, String scannerContent, String batch, String materielCode, String factoryCode, String inventoryAddressCode, String pickingClassify, String useDepartment, GsonBeanListener gsonBeanListener) {
        String tag;
        Map<String, String> params = new HashMap<>();
        params.put(IS_SCANNER, isSCanner ? "1" : "0");
        params.put(SCANNER_CONTENT, scannerContent == null ? "" : scannerContent);
        params.put(BATCH, batch == null ? "" : batch);
        params.put(MATERIEL_CODE, materielCode == null ? "" : materielCode);
        params.put(FACTORY_CODE, factoryCode == null ? "" : factoryCode);
        params.put(INVENTORY_ADDRESS_CODE, inventoryAddressCode == null ? "" : inventoryAddressCode);
        params.put(PICKING_CLASSIFY, pickingClassify == null ? "" : pickingClassify);
        params.put(USE_DEPARTMENT, useDepartment == null ? "" : useDepartment);
        String url = RequestManage.getUrl(context,RequestConstant.URL_OUT_STORAGE_PICKING_ADD_BATCH + RequestManage.mapEncodeToParams(params));
        tag = RequestManage.getHttpsGetWithLoading(context, url, new StringRequestListener() {
            @Override
            public void onSuccess(StringResponse stringRequestResponse) {
                Gson gson = new Gson();
                OutStoragePickingAddBatchBean bean = gson.fromJson(stringRequestResponse.getResponseInfo(), OutStoragePickingAddBatchBean.class);
                excuteJsonBean(context, bean, bean.getCode(), bean.getMsg(), gsonBeanListener);
            }
        });
        return tag;
    }

}
